package com.augn.service.impl;

import com.augn.entity.GoodsEvaluateFrom;
import com.augn.entity.Result;
import com.augn.entity.User;
import com.augn.mapper.GoodsEvaluateFromMapper;
import com.augn.mapper.GoodsEvaluateMainMapper;
import com.augn.service.IGoodsEvaluateFromService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static net.sf.jsqlparser.parser.feature.Feature.delete;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author augn
 * @since 2022-09-22
 */
@Service
public class GoodsEvaluateFromServiceImpl extends ServiceImpl<GoodsEvaluateFromMapper, GoodsEvaluateFrom> implements IGoodsEvaluateFromService {

    @Autowired
    private GoodsEvaluateFromMapper mapper;

    // 新增一个商品评论从评论
    @Override
    public Result<?> insertOneGoodsEvaluateFrom(GoodsEvaluateFrom goodsEvaluateFrom) {
        int insert = mapper.insert(goodsEvaluateFrom);
        if(insert==0){
            return Result.error("-1","新增失败");
        } else{
            return Result.success(insert);
        }
    }

    //删除一个商品评论从评论
    @Override
    public Result<?> deleteOneGoodsEvaluateFrom(Integer id) {
        int delete = mapper.deleteById(id);
        if(delete==0){
            return Result.error("-1","删除失败");
        } else{
            return Result.success(delete);
        }
    }

    // 根据商品主评论id获取商品从评论列表
    @Override
    public Result<?> getPartGoodsEvaluateFrom(Integer id) {
        QueryWrapper<GoodsEvaluateFrom> wrapper= new QueryWrapper<>();
        wrapper.eq("g_eva_main_id",id);
        List<GoodsEvaluateFrom> goodsEvaluateFromList = mapper.selectList(wrapper);
        if(goodsEvaluateFromList.isEmpty()){
            return Result.error("-1","暂无评论");
        } else{
            return Result.success(goodsEvaluateFromList);
        }
    }
}
